import { Navigate, useRoutes, useLocation } from "react-router-dom";
import homeRouter from "./modules/home";
import goodsRouter from "./modules/goods";
import mineRouter from "./modules/mine";
import Login from "../pages/login";
import notFound from "./modules/errors";
import { searchRoute } from "../units/units";


// * 导入所有router
//const metaRouters = import.meta.globEager("./modules/*.tsx");

// * 处理路由
// export const routerArray=[];
// Object.keys(metaRouters).forEach(item => {
// 	Object.keys(metaRouters[item]).forEach((key) => {
// 		routerArray.push(...metaRouters[item][key]);
// 	});
// });

const routers = homeRouter.concat(goodsRouter, mineRouter, notFound);



export const rootRouter = [
    {
        path: "/",
        element: <Navigate to="/login" />
    },
    {
        path: "/login",
        element: <Login />,
        meta: {
            requiresAuth: false,
            title: "登录页",
            key: "login"
        }
    },
    {
        path: "*",
        element: <Navigate to="/404" />
    },
    ...routers
];



const Router = () => {
    const routes = useRoutes(rootRouter);
    return routes;
};


export default Router;
